home *** CD-ROM | disk | FTP | other *** search
- global oASRObj, gMainLangModel, gCallBack, gSelectorLangModel, gTempLangModel, gMainLexSize, gMainLex, gMACListenStatus, gTempLexSize, gTempLexicon, gInputField, gdescfield, gIndxScrollFldK, gComputerTypeK, gVideoButtspr, gSelectorLex, gSelectorLexSize, gHuhCount, gESstartSND, oTextScroller, oIndexScroller, oINTERfaceFind, gPrevCommand, gBtnHitSND, gQTflag, gModeState, gTrekCursor, gSpeeButtSpr, gSpeeButtCastList, gWINListenStatus, gWinVoiceEnabled, gAudioButtspr, gWINvoiUserPermit, gSpeechCapable, gTempHyperlinks, gHoldSearchInfo, gResrcButtspr, oTextSlider, gImInHelp, gSpeechWasChosenF, gWinVoiceXobj, gTickSND, gFirstSpeechF
-
- on hInitRecongition
- hputmsg(">hInitRecongition begins==================================<")
- put "Determining voice recognition capability..." into field "Status"
- cursor(4)
- set gSpeechCapable to 0
- set gMainLangModel to 0
- set gTempLangModel to 0
- set gSelectorLangModel to 0
- set gTempLexicon to []
- set gMACListenStatus to 0
- set gPrevCommand to EMPTY
- if gComputerTypeK = #mac then
- if factory("ASRXObject") = 0 then
- set Lfilepath to the pathName & "ASR.XObj"
- if not hFileIsHere(Lfilepath) then
- hReportStatus("The file " & QUOTE & "ASR.XObj" & QUOTE & " must be present.")
- hearit(gNopeSND)
- cursor([gTrekCursor, gTrekCursor + 1])
- return 0
- end if
- openXLib(Lfilepath)
- end if
- set result to hStartASR()
- if result < 0 then
- hReportStatus("Speech recognition not enabled.")
- hearit(gNopeSND)
- else
- if gFirstSpeechF then
- go("OpC3")
- end if
- hearit(gBtnHitSND)
- hReportStatus("Loading primary command list...")
- hMakeMainCommandList()
- hReportStatus("Loading secondary command list...")
- hMakeSelectorList()
- set gSpeechCapable to 1
- put "Speech recognition sucessfully enabled." into field "Status"
- hUploadTempLinksLang()
- hUploadSelectorLang()
- hearit(gTickSND)
- hUploadMainLanguage()
- hearit(gTickSND)
- hSetLanguage(gMainLangModel)
- end if
- end if
- cursor([gTrekCursor, gTrekCursor + 1])
- end
-
- on hStartASR
- if objectp(oASRObj) then
- oASRObj(mdispose)
- end if
- set oASRObj to ASRXObject(mnew, factory("ASRCallBack"))
- set result to value(oASRObj)
- return result
- end
-
- on hRequestSpeechStatus
- if gComputerTypeK = #mac then
- if gMACListenStatus then
- if oASRObj(mStatus) > 1 then
- hShowSpeechStatus(#STANDBY)
- else
- hShowSpeechStatus(#READY)
- end if
- end if
- else
- if gComputerTypeK = #WIN then
- hWinVoiceIdle()
- end if
- end if
- end
-
- on hInitSpeeButts
- puppetSprite(gSpeeButtSpr, 1)
- set gSpeeButtCastList to [:]
- setaProp(gSpeeButtCastList, #INACTIVE, the number of cast "SPEECHavail")
- setaProp(gSpeeButtCastList, #STANDBY, the number of cast "SPEECHstandby")
- setaProp(gSpeeButtCastList, #READY, the number of cast "SPEECHready")
- setaProp(gSpeeButtCastList, #null, the number of cast "PixelREF")
- end
-
- on hShowSpeechStatus pMsg
- if pMsg = #STANDBY then
- hSysAlert(#null, 1)
- end if
- if pMsg = #READY then
- hSysAlert(#LCARSREADY, 1)
- end if
- end
-
- on hFlashSpeechStatus
- end
-
- on hStartListening pNoAnnc
- if gComputerTypeK = #WIN then
- hWinVoiceMicOn(0)
- else
- if objectp(oASRObj) then
- hReportStatus("Preparing speech recognizers...")
- set gMACListenStatus to 1
- oASRObj(mStartListening)
- hReportStatus("Speech ready...")
- if voidp(pNoAnnc) then
- hAnnounce("Voice Rec Activated")
- end if
- end if
- end if
- end
-
- on hUploadMainLanguage
- if gMainLangModel = 0 then
- set gMainLangModel to oASRObj(mNewLanguage, "<Main>")
- hPrepALanguage(gMainLangModel, gMainLexSize, gMainLex)
- end if
- end
-
- on hSafeRelease pLM
- if pLM then
- oASRObj(mRelease, pLM)
- end if
- return 0
- end
-
- on hSetLanguage pLM
- if pLM then
- oASRObj(mSetLanguage, pLM)
- end if
- end
-
- on hUploadSelectorLang
- if gSelectorLangModel = 0 then
- set gSelectorLangModel to oASRObj(mNewLanguage, "<Selectors>")
- hPrepALanguage(gSelectorLangModel, gSelectorLexSize, gSelectorLex)
- end if
- end
-
- on hPrepALanguage pLM, pSize, pList
- cursor(4)
- set Lerrmsg to 0
- repeat with i = 1 to pSize
- set Lerrmsg to oASRObj(mAddPhrase, pLM, getPropAt(pList, i), i)
- if Lerrmsg then
- exit repeat
- end if
- end repeat
- cursor([gTrekCursor, gTrekCursor + 1])
- if Lerrmsg then
- hReportStatus("Speech recognizer had trouble adding the phrase >" & getPropAt(pList, i))
- hearit(gNopeSND)
- end if
- end
-
- on hRestoreSpeech
- if gSpeechCapable = 0 then
- return
- end if
- if gSpeechWasChosenF = 1 then
- if gComputerTypeK = #mac then
- if gMACListenStatus = 0 then
- hStartListening(1)
- end if
- else
- if gComputerTypeK = #WIN then
- if hWinVoiceMicState() = 0 then
- hStartListening(1)
- end if
- end if
- end if
- end if
- end
-
- on hSwitchSpeech
- if gSpeechCapable = 0 then
- return
- end if
- if gComputerTypeK = #mac then
- if gMACListenStatus = 0 then
- set gSpeechWasChosenF to 1
- if not gFirstSpeechF then
- hInitRecongition()
- set gFirstSpeechF to 0
- end if
- hStartListening()
- else
- set gSpeechWasChosenF to 0
- set gFirstSpeechF to 0
- hStopListening()
- end if
- else
- if gComputerTypeK = #WIN then
- if not objectp(gWinVoiceXobj) then
- set gSpeechWasChosenF to 1
- hWinVoiceOpen(0)
- if gWinVoiceEnabled = 1 then
- put "ANNOUNCING FROM HSWITCHSPEECH"
- hAnnounce("Voice Rec Activated")
- end if
- else
- if hWinVoiceMicState() = 0 then
- set gSpeechWasChosenF to 1
- hStartListening()
- else
- set gSpeechWasChosenF to 0
- hWinVoiceMicOff()
- end if
- end if
- end if
- end if
- end
-
- on mDoRecognize phrase, phraseID
- global gMainLex
- hearit(gESstartSND)
- hReportStatus("Interpreting >" & phrase & "<")
- set Ltidl to the itemDelimiter
- set the itemDelimiter to ","
- set LthisPhr to value(item 1 of phraseID)
- if LthisPhr < 1 then
- put " which I dont understand." after field "Status"
- set gHuhCount to gHuhCount + 1
- if gHuhCount > 5 then
- if gHuhCount > 10 then
- hAnnounce("Please Specify")
- set gHuhCount to 0
- else
- if gHuhCount = 6 then
- hAnnounce("...Do not address...In that...")
- end if
- end if
- end if
- set the itemDelimiter to Ltidl
- return
- else
- set gHuhCount to 0
- end if
- hSysAlert(#null)
- if LthisPhr <= gMainLexSize then
- if LthisPhr > 2 then
- set the itemDelimiter to Ltidl
- do(string(getAt(gMainLex, LthisPhr)))
- hRememberThis(getAt(gMainLex, LthisPhr))
- else
- set LtheSubID to value(item 2 of phraseID)
- set the itemDelimiter to Ltidl
- if LthisPhr = 1 then
- do(string(getAt(gSelectorLex, LtheSubID)))
- hRememberThis(getAt(gSelectorLex, LtheSubID))
- else
- if LthisPhr = 2 then
- set tidl to the itemDelimiter
- set the itemDelimiter to "@"
- hInterpretSpecial(item LtheSubID of gTempHyperlinks, #ENCY)
- set the itemDelimiter to tidl
- else
- end if
- end if
- end if
- hSysAlert(#LCARSREADY)
- else
- hReportStatus("==Yeah? you want me to " & phrase & "!")
- end if
- end
-
- on hStopSpeech
- hStopListening()
- if gComputerTypeK = #WIN then
- hWinVoiceClose()
- else
- if objectp(oASRObj) then
- set gMainLangModel to hSafeRelease(gMainLangModel)
- set gTempLangModel to hSafeRelease(gTempLangModel)
- set gSelectorLangModel to hSafeRelease(gSelectorLangModel)
- oASRObj(mdispose)
- end if
- end if
- end
-
- on hStopListening
- if gComputerTypeK = #WIN then
- hWinVoiceMicOff()
- hShowSpeechStatus(#INACTIVE)
- else
- if objectp(oASRObj) then
- if not voidp(gSpeechWasChosenF) then
- hReportStatus("Speech recognition turned off...")
- end if
- oASRObj(mStopListening)
- set gMACListenStatus to 0
- hShowSpeechStatus(#INACTIVE)
- end if
- end if
- end
-
- on hMakeMainCommandList
- set gMainLex to [:]
- do(the text of cast "Lex Phrases - Main")
- set gMainLexSize to count(gMainLex)
- end
-
- on hMakeSelectorList
- set gSelectorLex to [:]
- sort(gSelectorLex)
- do(the text of cast "Lex Phrases - Selectors")
- set gSelectorLexSize to count(gSelectorLex)
- end
-
- on hReply pWhatStr
- if pWhatStr = #Dear then
- hAnnounce("You're Welcome, Darling")
- else
- if pWhatStr = #Pardon then
- hAnnounce("Not a replicator")
- else
- if pWhatStr = #HELLO then
- hReportStatus("Greetings to you.")
- else
- hAnnounce("You're welcome")
- hReportStatus(pWhatStr)
- end if
- end if
- end if
- end
-
- on hDoThatAgain
- do(string(gPrevCommand))
- end
-
- on hRememberThis pThis
- if not pThis contains "Do That Again" then
- set gPrevCommand to pThis
- end if
- end
-
- on hInterpretSpecial pChunk, pMode
- if pChunk = EMPTY then
- abort()
- end if
- set Ltarget to hcleanup(pChunk)
- put Ltarget into field gInputField
- hilite char 999 of field gInputField
- hDetectMode(Ltarget)
- hMiniFind()
- end
-
- factory ASRCallBack
- method mRecognize phrase, id
- mDoRecognize(phrase, id)
-